package com.adsanse.vipul;

import java.io.IOException;
import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.accounts.Account;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.google.api.client.googleapis.GoogleHeaders;
import com.google.api.client.http.HttpResponse;
import com.google.api.services.adsense.Adsense.Adclients.List;


public class main extends Activity
{
Account[] str;
String Token;
ProgressDialog ProgD; 
AuthHelper ath = new  AuthHelper();
GoogleHeaders hdr;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        
       
		 str =  ath.getAccounts(getApplicationContext());
     
	
    
    Button btn = (Button)findViewById(R.id.btnexe);
    
 
   
    
    btn.setOnClickListener(new View.OnClickListener() {
		
 		@Override
 		public void onClick(View arg0) {
 			new AsyncButtonClk().execute();
 			
 		}
 	});
  
        
    }
    

private class AsyncButtonClk extends AsyncTask<String, Void, Void> 
	{
		
		@Override
		protected void onPreExecute()
		{
		
			
		}

		@Override
		protected Void doInBackground(String... arg0) 
		{
			
			
			  Token = ath.getAuthToken(getApplicationContext(),"vipul.coool@gmail.com", main.this);
			   Log.d("TOKEN IS :- ", Token);
			   
		


			return null;
			}
		
		
		
		@Override
		protected void onPostExecute(Void result) 
		{
			
			postData();

		}

	}

public void postData() {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("https://www.google.com/accounts/ClientLogin");
    
    try {
        // Add your data
        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("Content-Type","application/x-www-form-urlencoded"));
        nameValuePairs.add(new BasicNameValuePair("accountType", "GOOGLE"));
        nameValuePairs.add(new BasicNameValuePair("Email", "bhavikpatelahm@gmail.com"));
        nameValuePairs.add(new BasicNameValuePair("Passwd","BhavikPatel123"));
        nameValuePairs.add(new BasicNameValuePair("service","adsense"));
        nameValuePairs.add(new BasicNameValuePair("source","MyApp-adsenseNotifier-1.0"));
        
        
      
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        org.apache.http.HttpResponse response = httpclient.execute(httppost);
        
      
        
      System.out.print(response.getAllHeaders());

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }
} 
}